<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <form action="#">
        <select name="1" id="s1">
            <option value="">请选择</option>
            <option value="1">1</option>
            <option value="2">2</option>
            <option value="3">3</option>
            <option value="4">4</option>
            <option value="5">5</option>
            <option value="6">6</option>
            <option value="7">7</option>
            <option value="8">8</option>
            <option value="9">9</option>
            <option value="10">10</option>
            <option value="11">11</option>
            <option value="12">12</option>
        </select>
        <select name="2" id="s2"></select>
    </form>
    <script>
        window.onload = initForm;
        window.onunload = function() {}

        function initForm() {
            document.getElementById("s1").selectIndex = 0;
            document.getElementById("s1").onchange = newOption;
        }

        function newOption() {
            //下面两个弹出框结果相同
            alert(document.getElementById("s1")[this.selectedIndex]);
            alert(document.getElementById("s1").options[this.selectedIndex]);
            var day = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 31, 30];
            var monstr = document.getElementById("s1").options[this.selectedIndex].value;
            alert(monstr);
            if (monstr != "") {
                var mon = parseInt(monstr);
                var s2 = document.getElementById("s2");
                s2.options.length = 0;
                for (var i = 0; i < day[mon - 1]; i++) {
                    s2.options[i] = new Option(i + 1);
                }
            }

        }
    </script>
</body>

</html>